// gzip压缩
const CompressionWebpackPlugin = require("compression-webpack-plugin");
module.exports = {
  publicPath: process.env.NODE_ENV === "production" ? "./" : "",
  outputDir: "dist",
  lintOnSave: false,
  productionSourceMap: false,
  configureWebpack: (config) => {
    //gzip压缩
    const productionGzipExtensions = ["html", "js", "css"];
      config.plugins.push(
        new CompressionWebpackPlugin({
          filename: "[path][base].gz",
          algorithm: "gzip",
          test: new RegExp("\\.(" + productionGzipExtensions.join("|") + ")$"),
          threshold: 10240, // 只有大小大于该值的资源会被处理 10240
          minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
          deleteOriginalAssets: false, // 删除原文件
        })
      )
    config["performance"] = {
      //打包文件大小配置
      maxEntrypointSize: 10000000,
      maxAssetSize: 30000000,
    };
  },
  // 热加载
  chainWebpack: (config) => {
    config.resolve.symlinks(true);
  },
  //定义scss全局变量
  css: {
    sourceMap: false,
    loaderOptions: {
      scss: {
        prependData: `@import "@/style/_common.scss";`,
      },
    },
  },
  // 配置开发环境api
  devServer: {
    overlay: {
      warnings: true,
      errors: true,
    },
    proxy: {
      "/proxy": {
        target: "http://81.70.42.119:40080", //测试
        // target: "", //生产
        changeOrigin: true,
        pathRewrite: {
          "^/proxy": "/",
        },
      },
      "/pro30518": {
        target: "http://81.70.42.119:40080", //测试
        // target: "", //生产
      },
    },
  },
};
